﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Geekees.Common.Controls;
using Geekees.Common.Utilities.Xml;

public partial class WebControls_TreeViewMonHocSanPham : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GenerateTree();
        }
    }

    private void GenerateTree()
    {
        string v_str_monhocID = Request.QueryString["monhocId"];
        int v_int_monhocID = 0;
        int.TryParse(v_str_monhocID, out v_int_monhocID);

        string v_str_sanphamID = Request.QueryString["spId"];
        int v_int_sanphamID = 0;
        int.TryParse(v_str_sanphamID, out v_int_sanphamID);

        ASTreeViewLinkNode nd = new ASTreeViewLinkNode("", "", "#", "frm");
        nd.NodeText = "Chưa có sản phẩm nào.";
        nd.EnableChildren = false;
        nd.EnableEditContextMenu = false;

       // ASTreeViewNode note;
         ASTreeViewLinkNode note;
        ASTreeViewLinkNode nl;
        foreach (DM_MON_HOC v_obj_DM_MON_HOC in Services.GetDsDM_MON_HOC())
        {
            if (v_int_monhocID == (int)v_obj_DM_MON_HOC.ID)
            {
                note = new ASTreeViewLinkNode("<strong><FONT color = red >" + v_obj_DM_MON_HOC.TEN_TIENG_VIET + "</FONT></strong>", v_obj_DM_MON_HOC.ID.ToString(), String.Format("~/F120.aspx?monhocId={0}", v_obj_DM_MON_HOC.ID), "");
            }
            else {
                note = new ASTreeViewLinkNode(v_obj_DM_MON_HOC.TEN_TIENG_VIET, v_obj_DM_MON_HOC.ID.ToString(), String.Format("~/F120.aspx?monhocId={0}", v_obj_DM_MON_HOC.ID), "");
            }
            List<DM_SAN_PHAM> lshNghanh = Services.GetDsDM_SAN_PHAMBy((int)v_obj_DM_MON_HOC.ID);
            if (lshNghanh.Count > 0)
            {
                foreach (DM_SAN_PHAM ng in lshNghanh)
                {
                    if ((v_int_monhocID == (int)v_obj_DM_MON_HOC.ID) && (v_int_sanphamID == (int)ng.ID))
                    {
                        nl = new ASTreeViewLinkNode("<strong><FONT color = red >" + ng.TEN_SAN_PHAM + "</FONT></strong>", ng.ID.ToString(), String.Format("~/F130.aspx?monhocId={0}&spId={1}", v_obj_DM_MON_HOC.ID, ng.ID), "");
                    }
                    else {
                        nl = new ASTreeViewLinkNode(ng.TEN_SAN_PHAM, ng.ID.ToString(), String.Format("~/F130.aspx?monhocId={0}&spId={1}", v_obj_DM_MON_HOC.ID, ng.ID), "");
                    }
                    
                    note.AppendChild(nl);
                }
            }
            else
            {
                note.AppendChild(nd);
            }
            astvMyTree.RootNode.AppendChild(note);
        }

        astvMyTree.ContextMenu.Visible = false;
        astvMyTree.EnableCheckbox = false;
    }
}